﻿

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Dictionary
{
    public partial class DictionaryConfig : AntdUI.Window
    {
        IniClass Ini = new IniClass();


        Dictionary<string, string> Dictlist = new Dictionary<string, string>();


        private AntdUI.Window window;
        public DictionaryConfig()
        {
            InitializeComponent();
            BindEventHandler();

            InitConfig();
        }

        List<string> GI__TechnologyList = new List<string>();
        List<string> GI__ProcessList = new List<string>();
        List<string> TestName1List = new List<string>();
        List<string> TestName2List = new List<string>();
        List<string> TestName3List = new List<string>();
        List<string> TestName4List = new List<string>();
        public void InitConfig()
        {
          int Count = Convert.ToInt32(Ini.IniReadValue("GI__Technology", "GI__TechnologyCount"));
            for (int i = 0; i < Count; i++)
            {
                GI__TechnologyList.Add(Ini.IniReadValue("GI__Technology", "GI__Technology" + (i + 1).ToString()));
            }

            Count = Convert.ToInt32(Ini.IniReadValue("GI__Process", "GI__ProcessCount").ToString());

            for (int i = 0; i < Count; i++) {

                GI__ProcessList.Add(Ini.IniReadValue("GI__Process", "GI__Process"+(i+1).ToString()));
            }

            Count = Convert.ToInt32(Ini.IniReadValue("TestName1", "TestName1Count"));
            for (int i = 0; i < Count; i++)
            {
                TestName1List.Add(Ini.IniReadValue("TestName1", "TestName1" + (i + 1).ToString()));
            }

            Count = Convert.ToInt32(Ini.IniReadValue("TestName2", "TestName2Count"));
            for (int i = 0; i < Count; i++)
            {
                TestName2List.Add(Ini.IniReadValue("TestName2", "TestName2" + (i + 1).ToString()));
            }

            Count = Convert.ToInt32(Ini.IniReadValue("TestName3", "TestName3Count"));
            for (int i = 0; i < Count; i++)
            {
                TestName3List.Add(Ini.IniReadValue("TestName3", "TestName3" + (i + 1).ToString()));
            }

            Count = Convert.ToInt32(Ini.IniReadValue("TestName4", "TestName4Count"));
            for (int i = 0; i < Count; i++)
            {
                TestName4List.Add(Ini.IniReadValue("TestName4", "TestName4" + (i + 1).ToString()));
            }
        }




        private void BindEventHandler()
        {
            window = this;
            //1.7.14开始,uploadDragger自带点击打开文件选择框
            uploadDragger.DragChanged += UploadDragger_DragChanged;
            uploadDragger.Multiselect = false;//允许多选文件
            uploadDragger.Filter = "InI Files (*.ini)|*.ini";
            uploadDragger.HandDragFolder = true;//是否支持拖拽，默认为true

        }


        private void UploadDragger_DragChanged(object sender, AntdUI.StringsEventArgs e)
        {
            Dictlist.Clear();
            string[] filePaths = e.Value;
            foreach (string path in filePaths)
            {
                try
                {
                    // 获取源文件的文件名（含扩展名）
                    string fileName = Path.GetFileName(path);
                    uploadDragger.TextDesc = fileName;
                    var parser = new IniParser();
                    var iniData = parser.Parse(path);

                    // 获取所有section和key-value
                    foreach (var section in iniData)
                    {
                        
                        foreach (var kvp in section.Value)
                        {

                            Dictlist.Add(section.Key + "" + kvp.Key, kvp.Value);
                            if (kvp.Key == "GI__Technology") { 
                            
                            }
                            else if (kvp.Key == "GI__Process") {

                                if (!GI__ProcessList.Contains(kvp.Value)) {

                                    AntdUI.Message.error(window, "GI__Process填写错误",null,5);
                                    return;
                                }
                                

                            }
                            else if (kvp.Key == "TestName1") {
                                if (!TestName1List.Contains(kvp.Value))
                                {
                                    AntdUI.Message.error(window, "TestName1填写错误", null, 5);
                                    return;
                                }
                            }
                            else if (kvp.Key == "TestName2") {

                                if (!TestName2List.Contains(kvp.Value))
                                {
                                    AntdUI.Message.error(window, "TestName2填写错误", null, 5);
                                    return;
                                }
                            }
                            else if (kvp.Key == "TestName3") {

                                if (!TestName3List.Contains(kvp.Value))
                                {
                                    AntdUI.Message.error(window, "TestName3填写错误", null, 5);
                                    return;
                                }
                            }
                            else if (kvp.Key == "TestName4") {

                                if (!TestName4List.Contains(kvp.Value))
                                {
                                    AntdUI.Message.error(window, "TestName4填写错误", null, 5);
                                    return;
                                }

                            }
                        }
                    }


                    AntdUI.Message.success(window, "信息填写无误！", autoClose: 3);
                }
                catch (Exception ex)
                {

                    AntdUI.Message.error(window, ex.Message, autoClose: 3);
                }

            }
        }


    }
}
